/* eslint-disable space-before-function-paren */
/*
 * @Author: Aaron
 * @Date: 2022-03-22 16:47:31
 * @LastEditors: yanMeng
 * @LastEditTime: 2022-10-11 16:06:05
 * @Description: file content
 * @FilePath: \ias_ui\src\views\coi\commonJs\publicMethod.js
 * @Company: 沃尔玛
 */
/**
 *判断批量操作是否超过数量
 *message, callBack, num = 50, dataList = false, key = 'id' dataList需要判断的数据不传或者false拿multipleSelection数组
 */
export const checkBoxFun = {
  methods: {
    // 校验批量数据
    checkQuantity(val, maxNum = 500) {
      const arr = val && Array.isArray(val) && val.length ? val : false
      const multipleSelection = arr || this.multipleSelection
      if (multipleSelection.length > maxNum) {
        this.$message({
          type: 'warning',
          message: `批量任务数量不能超过${maxNum}条`
        })
        return false
      } else return multipleSelection
    },
    open(message, callBack, num = 50, dataList = false, key = 'id', transObj = false, objKey = 'spuId') {
      const arr = this.checkQuantity(dataList, num)
      if (!arr) return
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const params = arr.map((_) => {
            if (transObj) {
              return {
                [objKey]: _[key],
                channelType: _['channelType'] || ''
              }
            }
            return _[key]
          })
          await callBack(params)
        })
        .catch(() => {})
    }
  }
}
